#include <amxmodx>
#include <umitem>
#include <engine>

new PLUGIN_NAME[] 	= "UM Item: BunnyHop"
new PLUGIN_AUTHOR[] 	= "Cheap_Suit"
new PLUGIN_VERSION[] 	= "1.1"

new bool:g_BunnyHop[33] 
public plugin_init() 
{
	register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR)
	register_item("Bunny Hop", "Auto jumping", 800)
}

public client_connect(id) {
	g_BunnyHop[id] = false
}

public Enable_Item(id) {
	g_BunnyHop[id] = true
}

public Disable_Item(id) {
	g_BunnyHop[id] = false
}

public client_PreThink(id)
{
	if(!is_user_connected(id) || !is_user_alive(id)) {
		return PLUGIN_CONTINUE
	}
	
	if(!g_BunnyHop[id]) {
		return PLUGIN_CONTINUE
	}

	entity_set_float(id, EV_FL_fuser2, 0.0)
	if(get_user_button(id) & IN_JUMP)
	{
		new Flags = entity_get_int(id, EV_INT_flags)
		if(Flags | FL_WATERJUMP && entity_get_int(id, EV_INT_waterlevel) < 2 && Flags & FL_ONGROUND)
		{
			new Float:fVelocity[3]
			entity_get_vector(id, EV_VEC_velocity, fVelocity)
			fVelocity[2] += 250.0
			entity_set_vector(id, EV_VEC_velocity, fVelocity)
			entity_set_int(id, EV_INT_gaitsequence, 6)
		}
	}
	return PLUGIN_CONTINUE
}
